-- This script processes medium length for events

-- author: cristina


raw = LOAD '$inputDir/event_trace.tab' USING PigStorage('\t') AS (event_id,component_id,node_id,platform_id,node_name,event_type,event_start_time,event_stop_time,event_end_reason);

-- build durations
duration = FOREACH raw GENERATE 'medium duration' as id, event_stop_time-event_start_time as dur;

-- group and average
grup = GROUP duration BY id;
rez = FOREACH grup GENERATE group, AVG(duration.dur) as avg;

STORE rez INTO 'mediumevents_avg.rez' USING PigStorage();
